#include <AST/expr/var/StructAST.hpp>
#include <global.hpp>

Struct::Struct(string name, llvm::SmallVector<Expr *> varList)
    : Var(
        std::move(name),
        true,
        false,
        false,
        nullptr,
        BasicType::IntTy) // XXX: 延迟初始化基类type
{
    llvm::SmallVector<Type *> typeList;
    for (Expr *expr : varList) {
        Var *var = dynamic_cast<Var *>(expr);
        assert(var != nullptr && "Type in a struct can not be unknown");
        this->varList.push_back(var);
        typeList.push_back(var->getType());
    }
    StructType *ty = StructType::create(theContext, typeList, this->name);
    StructDef def(this->name, ty);
    for (Var *var : this->varList) { def.addField(var->getName()); }
    theScope.insertStruct(this->name, std::move(def));
    this->type = ty;
}

llvm::Value *Struct::codegen() {
    return nullptr;
}
